<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let obj = {
        name: "李杨",
        age: 20
    }
    //给对象部署默认的接口机制
    obj[Symbol.iterator] = function () {
        // 初始下标值
        let index = 0;
        //把对象里面的值存储到一个数组里面
        let key = Object.keys(obj);
        //返回next函数
        return {
            next: () => {
                if (index < key.length) {
                    return { "value": key[index++], done: false }
                } else {
                    return { "value": undefined, done: true }
                }
            }
        }
    }

    for(k of obj){
        console.log(k);
    }
    </script>
</body>
</html>